#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "CommLayer.h"
#include "Complex.h"



	/** Constructors **/
	CommLayer::CommLayer(int argc, char * argv[]) {
		tag = 0;

  		MPI_Init(&argc, &argv);

		MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
		MPI_Comm_size(MPI_COMM_WORLD, &p);
		MPI_Get_processor_name(hostname,&namelength);
	
	}

	CommLayer::~CommLayer() {
  		MPI_Finalize();
	}


	void CommLayer::sendComplex(Complex *c, int toRank) { sendComplex(c,toRank,0); }
	void CommLayer::sendComplex(Complex *c, int toRank, int iTag) {

		MPI_Send(c,2,MPI_DOUBLE,toRank,iTag,MPI_COMM_WORLD);
	}



	void CommLayer::recvComplex(Complex *c, int fromRank) { recvComplex(c,fromRank,0); }
	void CommLayer::recvComplex(Complex *c, int fromRank, int iTag) {

		MPI_Recv(c,2, MPI_DOUBLE,fromRank,iTag,MPI_COMM_WORLD,&status);
	}




	/** Util Functions **/
	void CommLayer::sayHello() {
		printf("Greetings from %s my rank is %d!\n",hostname,my_rank);
	}
